<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
        <input type="text" placeholder="输入搜索用户名" v-model='searchName'>
      <ul>
        <li v-for="person in filterPersons" :key="person.id">
          id:{{person.id}}---name:{{person.name}}---age:{{person.age}}
        </li>
      </ul>
      &nbsp;&nbsp;&nbsp;<button @click="orderType='asc'">升序</button>&nbsp;&nbsp;&nbsp;
      <button @click="orderType='desc'">降序</button>&nbsp;&nbsp;&nbsp;
      <button @click="orderType='origin'">还原</button>&nbsp;&nbsp;&nbsp;
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          persons: [
            { id: 1, name: "jack", age: 18 },
            { id: 2, name: "rose", age: 16 },
            { id: 3, name: "tom", age: 20 },
            { id: 4, name: "jerry", age: 23 },
            { id: 5, name: "peiqi", age: 24 },
            { id: 6, name: "peihua", age: 10 },
          ],
          orderType:'origin',
          searchName:''
        },
        computed:{
            filterPersons() {
                const filterPersons=this.persons.filter(person=>{
                    return person.name.indexOf(this.searchName) !== -1
                })
                if(this.orderType==='origin') return filterPersons
                const sortPersons = filterPersons.sort((a,b)=>{
                    return this.orderType==='asc'?a.age-b.age:b.age-a.age
                })
                return sortPersons
            }
        }
      });
    </script>
  </body>
</html>
